habag33351 / [WM] Proff - DEV

// ==UserScript==
// @name        [WM] Proff - DEV
// @description n/a
// @version     23.7.29.0
// @author      Folky
// @namespace   https://github.com/folktroll/
// @license     MIT
// @match       https://*proff.*/*/*/*
// @run-at      document-start
// @grant       GM_setClipboard
// @grant       GM_xmlhttpRequest
// @grant       GM.xmlHttpRequest
// @grant       GM_registerMenuCommand
// @grant       GM_addStyle
// @grant       GM_getResourceText
// @grant       GM_openInTab
// ==/UserScript==

"use strict";(()=>{var S=Object.create;var v=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var P=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var j=(o,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let f of I(e))!D.call(o,f)&&f!==i&&v(o,f,{get:()=>e[f],enumerable:!(n=U(e,f))||n.enumerable});return o};var B=(o,e,i)=>(i=o!=null?S(R(o)):{},j(e||!o||!o.__esModule?v(i,"default",{value:o,enumerable:!0}):i,o));var E=P((x,m)=>{(function(o,e){typeof m=="object"&&m.exports?m.exports=e():o.Toastify=e()})(x,function(o){var e=function(t){return new e.lib.init(t)},i="1.12.0";e.defaults={oldestFirst:!0,text:"Toastify is awesome!",node:void 0,duration:3e3,selector:void 0,callback:function(){},destination:void 0,newWindow:!1,close:!1,gravity:"toastify-top",positionLeft:!1,position:"",backgroundColor:"",avatar:"",className:"",stopOnFocus:!0,onClick:function(){},offset:{x:0,y:0},escapeMarkup:!0,ariaLive:"polite",style:{background:""}},e.lib=e.prototype={toastify:i,constructor:e,init:function(t){return t||(t={}),this.options={},this.toastElement=null,this.options.text=t.text||e.defaults.text,this.options.node=t.node||e.defaults.node,this.options.duration=t.duration===0?0:t.duration||e.defaults.duration,this.options.selector=t.selector||e.defaults.selector,this.options.callback=t.callback||e.defaults.callback,this.options.destination=t.destination||e.defaults.destination,this.options.newWindow=t.newWindow||e.defaults.newWindow,this.options.close=t.close||e.defaults.close,this.options.gravity=t.gravity==="bottom"?"toastify-bottom":e.defaults.gravity,this.options.positionLeft=t.positionLeft||e.defaults.positionLeft,this.options.position=t.position||e.defaults.position,this.options.backgroundColor=t.backgroundColor||e.defaults.backgroundColor,this.options.avatar=t.avatar||e.defaults.avatar,this.options.className=t.className||e.defaults.className,this.options.stopOnFocus=t.stopOnFocus===void 0?e.defaults.stopOnFocus:t.stopOnFocus,this.options.onClick=t.onClick||e.defaults.onClick,this.options.offset=t.offset||e.defaults.offset,this.options.escapeMarkup=t.escapeMarkup!==void 0?t.escapeMarkup:e.defaults.escapeMarkup,this.options.ariaLive=t.ariaLive||e.defaults.ariaLive,this.options.style=t.style||e.defaults.style,t.backgroundColor&&(this.options.style.background=t.backgroundColor),this},buildToast:function(){if(!this.options)throw"Toastify is not initialized";var t=document.createElement("div");t.className="toastify on "+this.options.className,this.options.position?t.className+=" toastify-"+this.options.position:this.options.positionLeft===!0?(t.className+=" toastify-left",console.warn("Property `positionLeft` will be depreciated in further versions. Please use `position` instead.")):t.className+=" toastify-right",t.className+=" "+this.options.gravity,this.options.backgroundColor&&console.warn('DEPRECATION NOTICE: "backgroundColor" is being deprecated. Please use the "style.background" property.');for(var r in this.options.style)t.style[r]=this.options.style[r];if(this.options.ariaLive&&t.setAttribute("aria-live",this.options.ariaLive),this.options.node&&this.options.node.nodeType===Node.ELEMENT_NODE)t.appendChild(this.options.node);else if(this.options.escapeMarkup?t.innerText=this.options.text:t.innerHTML=this.options.text,this.options.avatar!==""){var c=document.createElement("img");c.src=this.options.avatar,c.className="toastify-avatar",this.options.position=="left"||this.options.positionLeft===!0?t.appendChild(c):t.insertAdjacentElement("afterbegin",c)}if(this.options.close===!0){var s=document.createElement("button");s.type="button",s.setAttribute("aria-label","Close"),s.className="toast-close",s.innerHTML="&#10006;",s.addEventListener("click",function(h){h.stopPropagation(),this.removeElement(this.toastElement),window.clearTimeout(this.toastElement.timeOutValue)}.bind(this));var a=window.innerWidth>0?window.innerWidth:screen.width;(this.options.position=="left"||this.options.positionLeft===!0)&&a>360?t.insertAdjacentElement("afterbegin",s):t.appendChild(s)}if(this.options.stopOnFocus&&this.options.duration>0){var l=this;t.addEventListener("mouseover",function(h){window.clearTimeout(t.timeOutValue)}),t.addEventListener("mouseleave",function(){t.timeOutValue=window.setTimeout(function(){l.removeElement(t)},l.options.duration)})}if(typeof this.options.destination<"u"&&t.addEventListener("click",function(h){h.stopPropagation(),this.options.newWindow===!0?window.open(this.options.destination,"_blank"):window.location=this.options.destination}.bind(this)),typeof this.options.onClick=="function"&&typeof this.options.destination>"u"&&t.addEventListener("click",function(h){h.stopPropagation(),this.options.onClick()}.bind(this)),typeof this.options.offset=="object"){var p=n("x",this.options),d=n("y",this.options),u=this.options.position=="left"?p:"-"+p,L=this.options.gravity=="toastify-top"?d:"-"+d;t.style.transform="translate("+u+","+L+")"}return t},showToast:function(){this.toastElement=this.buildToast();var t;if(typeof this.options.selector=="string"?t=document.getElementById(this.options.selector):this.options.selector instanceof HTMLElement||typeof ShadowRoot<"u"&&this.options.selector instanceof ShadowRoot?t=this.options.selector:t=document.body,!t)throw"Root element is not defined";var r=e.defaults.oldestFirst?t.firstChild:t.lastChild;return t.insertBefore(this.toastElement,r),e.reposition(),this.options.duration>0&&(this.toastElement.timeOutValue=window.setTimeout(function(){this.removeElement(this.toastElement)}.bind(this),this.options.duration)),this},hideToast:function(){this.toastElement.timeOutValue&&clearTimeout(this.toastElement.timeOutValue),this.removeElement(this.toastElement)},removeElement:function(t){t.className=t.className.replace(" on",""),window.setTimeout(function(){this.options.node&&this.options.node.parentNode&&this.options.node.parentNode.removeChild(this.options.node),t.parentNode&&t.parentNode.removeChild(t),this.options.callback.call(t),e.reposition()}.bind(this),400)}},e.reposition=function(){for(var t={top:15,bottom:15},r={top:15,bottom:15},c={top:15,bottom:15},s=document.getElementsByClassName("toastify"),a,l=0;l<s.length;l++){f(s[l],"toastify-top")===!0?a="toastify-top":a="toastify-bottom";var p=s[l].offsetHeight;a=a.substr(9,a.length-1);var d=15,u=window.innerWidth>0?window.innerWidth:screen.width;u<=360?(s[l].style[a]=c[a]+"px",c[a]+=p+d):f(s[l],"toastify-left")===!0?(s[l].style[a]=t[a]+"px",t[a]+=p+d):(s[l].style[a]=r[a]+"px",r[a]+=p+d)}return this};function n(t,r){return r.offset[t]?isNaN(r.offset[t])?r.offset[t]:r.offset[t]+"px":"0px"}function f(t,r){return!t||typeof r!="string"?!1:!!(t.className&&t.className.trim().split(/\s+/gi).indexOf(r)>-1)}return e.lib.init.prototype=e.lib,e})});var N=B(E(),1);var H=".toastify{background:linear-gradient(135deg,#73a5ff,#5477f5);border-radius:2px;box-shadow:0 3px 6px -1px rgba(0,0,0,.12),0 10px 36px -4px rgba(77,96,232,.3);color:#fff;cursor:pointer;display:inline-block;max-width:calc(50% - 20px);opacity:0;padding:12px 20px;position:fixed;-webkit-text-decoration:none;text-decoration:none;transition:all .4s cubic-bezier(.215,.61,.355,1);z-index:2147483647}.toastify.on{opacity:1}.toast-close{background:transparent;border:0;color:#fff;cursor:pointer;font-family:inherit;font-size:1em;opacity:.4;padding:0 5px}.toastify-right{right:15px}.toastify-left{left:15px}.toastify-top{top:-150px}.toastify-bottom{bottom:-150px}.toastify-rounded{border-radius:25px}.toastify-avatar{border-radius:2px;height:1.5em;margin:-7px 5px;width:1.5em}.toastify-center{left:0;margin-left:auto;margin-right:auto;max-width:fit-content;max-width:-moz-fit-content;right:0}@media only screen and (max-width:360px){.toastify-left,.toastify-right{left:0;margin-left:auto;margin-right:auto;max-width:-moz-fit-content;max-width:fit-content;right:0}}";document.head.appendChild(document.createElement("style")).appendChild(document.createTextNode(H));var w={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u1EA4:"A",\u1EAE:"A",\u1EB2:"A",\u1EB4:"A",\u1EB6:"A",\u00C6:"AE",\u1EA6:"A",\u1EB0:"A",\u0202:"A",\u00C7:"C",\u1E08:"C",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u1EBE:"E",\u1E16:"E",\u1EC0:"E",\u1E14:"E",\u1E1C:"E",\u0206:"E",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u1E2E:"I",\u020A:"I",\u00D0:"D",\u00D1:"N",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u1ED0:"O",\u1E4C:"O",\u1E52:"O",\u020E:"O",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00DD:"Y",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u1EA5:"a",\u1EAF:"a",\u1EB3:"a",\u1EB5:"a",\u1EB7:"a",\u00E6:"ae",\u1EA7:"a",\u1EB1:"a",\u0203:"a",\u00E7:"c",\u1E09:"c",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u1EBF:"e",\u1E17:"e",\u1EC1:"e",\u1E15:"e",\u1E1D:"e",\u0207:"e",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u1E2F:"i",\u020B:"i",\u00F0:"d",\u00F1:"n",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u1ED1:"o",\u1E4D:"o",\u1E53:"o",\u020F:"o",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00FD:"y",\u00FF:"y",\u0100:"A",\u0101:"a",\u0102:"A",\u0103:"a",\u0104:"A",\u0105:"a",\u0106:"C",\u0107:"c",\u0108:"C",\u0109:"c",\u010A:"C",\u010B:"c",\u010C:"C",\u010D:"c",C\u0306:"C",c\u0306:"c",\u010E:"D",\u010F:"d",\u0110:"D",\u0111:"d",\u0112:"E",\u0113:"e",\u0114:"E",\u0115:"e",\u0116:"E",\u0117:"e",\u0118:"E",\u0119:"e",\u011A:"E",\u011B:"e",\u011C:"G",\u01F4:"G",\u011D:"g",\u01F5:"g",\u011E:"G",\u011F:"g",\u0120:"G",\u0121:"g",\u0122:"G",\u0123:"g",\u0124:"H",\u0125:"h",\u0126:"H",\u0127:"h",\u1E2A:"H",\u1E2B:"h",\u0128:"I",\u0129:"i",\u012A:"I",\u012B:"i",\u012C:"I",\u012D:"i",\u012E:"I",\u012F:"i",\u0130:"I",\u0131:"i",\u0132:"IJ",\u0133:"ij",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u1E30:"K",\u1E31:"k",K\u0306:"K",k\u0306:"k",\u0139:"L",\u013A:"l",\u013B:"L",\u013C:"l",\u013D:"L",\u013E:"l",\u013F:"L",\u0140:"l",\u0141:"l",\u0142:"l",\u1E3E:"M",\u1E3F:"m",M\u0306:"M",m\u0306:"m",\u0143:"N",\u0144:"n",\u0145:"N",\u0146:"n",\u0147:"N",\u0148:"n",\u0149:"n",N\u0306:"N",n\u0306:"n",\u014C:"O",\u014D:"o",\u014E:"O",\u014F:"o",\u0150:"O",\u0151:"o",\u0152:"OE",\u0153:"oe",P\u0306:"P",p\u0306:"p",\u0154:"R",\u0155:"r",\u0156:"R",\u0157:"r",\u0158:"R",\u0159:"r",R\u0306:"R",r\u0306:"r",\u0212:"R",\u0213:"r",\u015A:"S",\u015B:"s",\u015C:"S",\u015D:"s",\u015E:"S",\u0218:"S",\u0219:"s",\u015F:"s",\u0160:"S",\u0161:"s",\u0162:"T",\u0163:"t",\u021B:"t",\u021A:"T",\u0164:"T",\u0165:"t",\u0166:"T",\u0167:"t",T\u0306:"T",t\u0306:"t",\u0168:"U",\u0169:"u",\u016A:"U",\u016B:"u",\u016C:"U",\u016D:"u",\u016E:"U",\u016F:"u",\u0170:"U",\u0171:"u",\u0172:"U",\u0173:"u",\u0216:"U",\u0217:"u",V\u0306:"V",v\u0306:"v",\u0174:"W",\u0175:"w",\u1E82:"W",\u1E83:"w",X\u0306:"X",x\u0306:"x",\u0176:"Y",\u0177:"y",\u0178:"Y",Y\u0306:"Y",y\u0306:"y",\u0179:"Z",\u017A:"z",\u017B:"Z",\u017C:"z",\u017D:"Z",\u017E:"z",\u017F:"s",\u0192:"f",\u01A0:"O",\u01A1:"o",\u01AF:"U",\u01B0:"u",\u01CD:"A",\u01CE:"a",\u01CF:"I",\u01D0:"i",\u01D1:"O",\u01D2:"o",\u01D3:"U",\u01D4:"u",\u01D5:"U",\u01D6:"u",\u01D7:"U",\u01D8:"u",\u01D9:"U",\u01DA:"u",\u01DB:"U",\u01DC:"u",\u1EE8:"U",\u1EE9:"u",\u1E78:"U",\u1E79:"u",\u01FA:"A",\u01FB:"a",\u01FC:"AE",\u01FD:"ae",\u01FE:"O",\u01FF:"o",\u00DE:"TH",\u00FE:"th",\u1E54:"P",\u1E55:"p",\u1E64:"S",\u1E65:"s",X\u0301:"X",x\u0301:"x",\u0403:"\u0413",\u0453:"\u0433",\u040C:"\u041A",\u045C:"\u043A",A\u030B:"A",a\u030B:"a",E\u030B:"E",e\u030B:"e",I\u030B:"I",i\u030B:"i",\u01F8:"N",\u01F9:"n",\u1ED2:"O",\u1ED3:"o",\u1E50:"O",\u1E51:"o",\u1EEA:"U",\u1EEB:"u",\u1E80:"W",\u1E81:"w",\u1EF2:"Y",\u1EF3:"y",\u0200:"A",\u0201:"a",\u0204:"E",\u0205:"e",\u0208:"I",\u0209:"i",\u020C:"O",\u020D:"o",\u0210:"R",\u0211:"r",\u0214:"U",\u0215:"u",B\u030C:"B",b\u030C:"b",\u010C\u0323:"C",\u010D\u0323:"c",\u00CA\u030C:"E",\u00EA\u030C:"e",F\u030C:"F",f\u030C:"f",\u01E6:"G",\u01E7:"g",\u021E:"H",\u021F:"h",J\u030C:"J",\u01F0:"j",\u01E8:"K",\u01E9:"k",M\u030C:"M",m\u030C:"m",P\u030C:"P",p\u030C:"p",Q\u030C:"Q",q\u030C:"q",\u0158\u0329:"R",\u0159\u0329:"r",\u1E66:"S",\u1E67:"s",V\u030C:"V",v\u030C:"v",W\u030C:"W",w\u030C:"w",X\u030C:"X",x\u030C:"x",Y\u030C:"Y",y\u030C:"y",A\u0327:"A",a\u0327:"a",B\u0327:"B",b\u0327:"b",\u1E10:"D",\u1E11:"d",\u0228:"E",\u0229:"e",\u0190\u0327:"E",\u025B\u0327:"e",\u1E28:"H",\u1E29:"h",I\u0327:"I",i\u0327:"i",\u0197\u0327:"I",\u0268\u0327:"i",M\u0327:"M",m\u0327:"m",O\u0327:"O",o\u0327:"o",Q\u0327:"Q",q\u0327:"q",U\u0327:"U",u\u0327:"u",X\u0327:"X",x\u0327:"x",Z\u0327:"Z",z\u0327:"z"},C=Object.keys(w).join("|"),z=new RegExp(C,"g"),J=new RegExp(C,""),W=o=>w[o],F=o=>o.replace(z,W);var k=F;var g={},O=document.location.href,y={no:{main:"rolle",details:"roller",beta:!0},se:{main:"befattning",details:"befattningshavare",beta:!1},dk:{main:"rolle",details:"roller",beta:!1},fi:{main:"rooli",details:"rooli",beta:!1}},G=100,V={"Daglig leder":"CEO","Styrets leder":"Chairman",Styremedlem:"Board Member",Varamedlem:"Deputy Board Member",Nestleder:"Deputy Chairman","Verkst\xE4llande direkt\xF6r":"CEO",Ordf\u00F6rande:"Chairman",Ledamot:"Board Member",Suppleant:"Deputy Board Member","Extern verkst\xE4llande direkt\xF6r":"CEO","Extern vice verkst\xE4llande direkt\xF6r":"Deputy CEO","Adm. direkt\xF8r":"CEO",Direkt\u00F8r:"Director",Bestyrelsesformand:"Chairman",Bestyrelsesmedlem:"Director",Stifter:"founder",N\u00E6stformand:"Deputy Chairman"},$={AE:"Ae"},K=["Innehaver","Kontaktperson","Innehavare","Arbetstagarrepresentant","Extern firmatecknare","Huvudansvarig revisor","Kommanditdel\xE4gare","Deltaker med delt ansvar","Observat\xF8r","Deltaker med fullt ansvar","Forretningsf\xF8rer","Norsk representant for utenlandsk enhet","Komplement\xE4r","Bolagsman","Revisor","Revisorssuppleant","Fuldt ansvarlig deltager"],X={"Chairman, Board Member":"Chairman","Chairman, CEO, Board Member":"Chairman, CEO","Director, Director":"Director"};GM_addStyle(GM_getResourceText("toastifyCSS")+"div.toastify { margin-top: 120px; width: inherit; font-family: Calibri, Candara, Segoe, Segoe UI, Optima, Arial, sans-serif; }");var T=()=>{let{host:o,pathname:e}=document.location,i=o.split(".").at(-1)||"";if(y[i]?.beta===!0&&o.split(".").at(0)!=="beta")return document.location.replace(`https://beta.proff.${i}/${e}`),-1;let n=e.split("/").at(1)?.includes(y[i].main),f=e.split("/").at(1)?.includes(y[i].details),t=-1;return(n||f)&&(t=Number(e.split("/").at(4))),t===-1&&console.log("missing ID:",e),t},M=()=>{let o=T();return Object.prototype.hasOwnProperty.call(g,`${o}`)||(console.log("Creating empty profile cache"),g[o]={totalExp:0,copyStr:"",json:[],isReady:!1}),g[o]||void 0},b=(o=0,e=100)=>{let i=T();if(!(Number(i)>0)){console.log("Missing profId:",i);return}let n=M(),t=`${document.location.origin}/api/persons/businessperson/${i}/roles?offset=${o}&limit=${e}`;if(console.log("fetchUrl:",t),n.copyStr.length>0){A();return}GM.xmlHttpRequest({method:"GET",url:t,responseType:"json",onload:r=>{if(r.status===200)try{let c=r.response;if(n.json.push(...c),console.log("OPA COUNT:",c.length),n.json.length%G===0)b(n.json.length);else{let s={},a=0;for(let p of n.json){let d=p.companyName,u=p.roleName;K.includes(u)||(s[d]&&s[d].indexOf(u)===-1?s[d].push(u):s[d]=[u])}let l="";Object.entries(s).forEach(([p,d])=>{l+=Y(p,d.join(", "))}),n.name=document.querySelector("h1.MuiTypography-root")?.innerHTML.trim()||"Unknown",n.copyStr=_(l),n.totalExp=n.copyStr.split(`\r
`).length-1,n.isReady=!0,A()}}catch(c){console.log("Error:",c);return}}})},Y=(o,e)=>{o.includes("\xB7")&&(o=o.substring(0,o.indexOf("\xB7")).trim()),e=e.replace(/[_]+/g,"");let i=`- ${o.trim()}, ${e.trim()}`;return i=i.replace(/\s+/g," ")+`\r
`,i},_=o=>(Object.entries(V).forEach(([e,i])=>{o=o.replaceAll(e,i)}),o=k(o),Object.entries($).forEach(([e,i])=>{o=o.replaceAll(e,i)}),Object.entries(X).forEach(([e,i])=>{o=o.replaceAll(e,i)}),o),A=()=>{console.log("\u{1F37A} Profiles info:",g);let o=M();console.log(`Text is ready:
`,o.copyStr);let e=(0,N.default)({text:`<b><i>${o.name}</i></b>: ${o.totalExp} exp.`,duration:15e3,stopOnFocus:!0,escapeMarkup:!1,close:!1,gravity:"top",position:"right",style:{padding:"10px",background:"rgb(5, 118, 66, 0.8)",color:"#ddd","font-weight":"500","border-radius":"50px","min-width":"300px","text-align":"center","font-variant":"small-caps",selector:"div.application-outlet"},onClick:()=>{GM_setClipboard(o.copyStr),e.hideToast()}}).showToast();GM_registerMenuCommand(`${o.name}: Copy all ${o.totalExp} positions`,()=>{GM_setClipboard(o.copyStr)})};window.addEventListener("load",()=>{new MutationObserver(()=>{O!==document.location.href&&(O=document.location.href,console.log("URL Changed!"),b())}).observe(document.body,{subtree:!0,childList:!0})});b();})();